home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / math / cephes22 / cmath / mthutl.c < prev    next >
Encoding:
Text File  |  1992-11-16  |  14.2 KB  |  499 lines

  1.  := 0;
  2.       end;
  3.     end;
  4.   end;
  5.   WaitToGo;
  6. end; { UserLineStylePlay }
  7.  
  8.  
  9. procedure SayGoodbye;
  10. { Say goodbye and then exit the program }
  11. var
  12.   ViewInfo : ViewPortType;
  13. begin
  14.   MainWindow('');
  15.   GetViewSettings(ViewInfo);
  16.   SetTextStyle(TriplexFont, HorizDir, 4);
  17.   SetTextJustify(CenterText, CenterText);
  18.   with ViewInfo do
  19.     OutTextXY((x2-x1) div 2, (y2-y1) div 2, 'That''s all folks!');
  20.   StatusLine('Press any key to quit...');
  21.   repeat until KeyPressed;
  22. end; { SayGoodbye }
  23.  
  24.  
  25. PROCEDURE SelectMode;
  26. VAR
  27.     choice1,choice2     : CHAR;
  28.    xsize,ysize            : WORD;
  29. BEGIN
  30.     (* Let's select a mode *)
  31.     ClrScr;
  32.     WriteLn('VESADEMO:');
  33.     WriteLn('1. 256 colors');
  34.     WriteLn('2. 32768 colors');
  35.     WriteLn('3. 65536 colors');
  36.     WriteLn('4. 16777216 colors');
  37.     WriteLn('Q uit');
  38.     WriteLn;
  39.     Write('Your choice: ');
  40.     REPEAT
  41.         ReadLn(choice1);
  42.       IF choice1 <> '1' THEN BEGIN
  43.           WriteLn('Sorry !');
  44.          WriteLn('This demo wasn''t written for more as 256 colors !');
  45.          WriteLn('You would only get a limited impression of the Hi-& TrueColor modes...');
  46.          WriteLn('Switching to 256 colors.');
  47.          choice1 := '1';
  48.       END;
  49.     UNTIL choice1 IN ['1'..'4','q'];
  50.     IF choice1 = 'q' THEN Halt;
  51.  
  52.     WriteLn;
  53.     WriteLn;
  54.     WriteLn('a. 320x200');
  55.     WriteLn('b. 640x480');
  56.     WriteLn('c. 800x600');
  57.     WriteLn('d. 1024x768');
  58.     WriteLn('e. 1280x1024');
  59.     WriteLn('Q uit');
  60.     WriteLn;
  61.     Write('Your choice: ');
  62.     REPEAT
  63.         ReadLn(choice2);
  64.     UNTIL choice2 IN ['a'..'e','q'];
  65.     IF choice2 = 'q' THEN Halt;
  66.  
  67.     CASE choice2 OF
  68.         'a' : BEGIN
  69.             xsize := 320;
  70.             ysize := 200;
  71.         END;
  72.         'b' : BEGIN
  73.             xsize := 640;
  74.             ysize := 480;
  75.         END;
  76.         'c' : BEGIN
  77.             xsize := 800;
  78.             ysize := 600;
  79.         END;
  80.         'd' : BEGIN
  81.             xsize := 1024;
  82.             ysize := 768;
  83.         END;
  84.         'e' : BEGIN
  85.             xsize := 1280;
  86.             ysize := 1024;
  87.         END;
  88.     END;
  89.     CASE choice1 OF
  90.         '1' : mode := FindVesaMode(xsize,ysize,8);
  91.         '2' : mode := FindVesaMode(xsize,ysize,15);
  92.         '3' : mode := FindVesaMode(xsize,ysize,16);
  93.         '4' : mode := FindVesaMode(xsize,ysize,24);
  94.     END;
  95.     IF mode = 0 THEN BEGIN
  96.         WriteLn('No such mode could be found !');
  97.         WriteLn('Switching to to 320x200.');
  98.         ReadKey;
  99.         mode := V320x200x256;
  100.     END;
  101. END;
  102.  
  103. begin { program body }
  104.   SelectMode;
  105.   Initialize;
  106.   ReportStatus;
  107.  
  108. {  AspectRatioPlay; }
  109.   FillEllipsePlay;
  110.   SectorPlay;
  111.   WriteModePlay;
  112.  
  113.   ColorPlay;
  114.   { PalettePlay only intended to work on these drivers: }
  115.   if (GraphDriver = EGA) or
  116.       (GraphDriver = EGA64) or
  117.       (GraphDriver = VGA) then
  118.      PalettePlay;
  119.   PutPixelPlay;
  120. {  PutImagePlay; }
  121.   RandBarPlay;
  122.   BarPlay;
  123.   Bar3DPlay;
  124.   ArcPlay;
  125.   CirclePlay;
  126.   PiePlay;
  127.   LineToPlay;
  128.   LineRelPlay;
  129. {  LineStylePlay; }
  130. {  UserLineStylePlay; }
  131.   TextDump;
  132.   TextPlay;
  133.   CrtModePlay;
  134.   FillStylePlay;
  135.   FillPatternPlay;
  136.   PolyPlay;
  137.   SayGoodbye;
  138. {  CloseGraph; }
  139.   CloseVesa;
  140. end.
  141. ***************************************************
  142.     '* SHOW D2ROTATE (ABOUT THE ORIGIN)
  143.     '****************************************************************∞╥≤c≤*φè#^│v/╒:j═φ0t+l▓ô"¬"g└≡?%ªêΣ│H╫½╫╜├¿U'╒⌐⌡ ßV?╩
  144. ¬ujOΦçEZ1∞▐! ▄B╛Σ8║æ]1GlNÜ┐q▌▓;ô$ΦzE<cª*bEô#ä╧ñÅ"∩─LrdaÖ ╠º╫a^¥£å╬1~)@ëÖMδ╫0═6DäFê¬Çv┼ß╨kæpτ╪É)}ª 1w3╤╧ü⌡¥╓h▓╣≈ïÅaÑ[TⁿHqªÉ╝DKÄ─Y-∞tT╤Θ╨º╟╪.*ÇI9lΦ≈{πτcσ$τπßoFr╪╨∩┼╞╟;O2■e²LÜ4^N|╪½ÅO?╔°FOz`╟╟╟'<>>π$πΘù6·
  145. Xgî╖│°oîδπGƒd╝▀░?■╪╔_9L ⌡ôⁿq'æO▀ƒn4╔▀╚▄┼3pτ.òO°·}÷╕ⁿ±'æO?ít│!√8ßÑ≤/┐╣p┼≥┘E╦Vox╕cΦé5╟╚º╙$?√$≥ΘZεsî≡åìΓpKù¢ïß X╥ 9╞≈\µk┤O¥_ 5Üö\≤éÄ┌╤A[╤ÿáï┼éNⁿÅu16    g,%hc╙╨cD╨Vï┘R¢öKñR;8εáΣ╢╪ós╤π╡á└èxgzPÄMú╫yαºÉ+σJ¢i+▓â3╥    ═Ñ╙î^ºG▓█πérφçs %#(╗⌠?┼%u8≡6+QÉ))ò)Afw≈╣╪)B&4░åLXV:δät@Å.;5Φf╢Ät┐ΣJ╫─U8úÇ╟éö£╕p╔┴⌠vg╨╬╥é÷╪╣┬ΓI.ç≡^v╤ZΦÇ& ╒┌6ñô6XßNè╡╬E₧Ñ
  146. kIº╠▄A+╣╥éb²tæ-Y¡½αÑa═uuîÇ╢αêvhuª╡SÅ┤vèùú¥F;p<d⌐/F─d█éT%▓KΦû=q■öI┐ ┐╠6S$▒÷╚ENΩ¥Fû9╔┌R'╝ ╧φ└?g┬j▓0═/b╖₧─mûé╢┌»ÿÄë/·<éò■░╤╟╢├Xσ:╥P3Θ"╬Læsφ░┌öSö!╗¿*mN£WΣÇ£┤~#╗ææ≥RΩóh:à▌.æ≈╕▌v£äàd▒à╒├=░╖π║$howeg*╬    6ù▄ƒô╕φ░Ö╢qΘD>(w@úKεHÆ╛öúΣU
  147. éÜR╔╤W▄èê 2M%ó.▓SNÖA1ùJE╢║l]▓¿>\%└Å4ßO▄£â⌐& ê/)8vSP▀▓ôⁿææ√ü√ÑÄa⌠â╚4S╓╟P- ?Σá╕▓Næ*q╡UΘ▓≈^ñ·I.rúR&$Y^╚%è≡B┌≈Ceat
  148.     Color := RandColor;
  149.     SetColor(Color);
  150.     SetFillStyle(Random(CloseDotFill)+1, Color);
  151.     Bar3D(Random(MaxWidth), Random(MaxHeight),
  152.           Random(MaxWidth), Random(MaxHeight), 0, TopOff);
  153.   until KeyPressed;
  154.   WaitToGo;
  155. end; { RandBarPlay }
  156.  
  157. procedure ArcPlay;
  158. { Draw random arcs on the screen }
  159. var
  160.   MaxRadius : word;
  161.   EndAngle : word;
  162.   ArcInfo : ArcCoordsType;
  163. begin
  164.   MainWindow('Arc / GetArcCoords demonstration');
  165.   StatusLine('Esc aborts or press a key');
  166.   MaxRadius := MaxY div 10;
  167.   repeat
  168.     SetColor(RandColor);
  169.     EndAngle := Random(360);
  170.     SetLineStyle(SolidLn, 0, NormWidth);
  171.     Arc(Random(MaxX), Random(MaxY), Random(EndAngle), EndAngle, Random(MaxRadius));
  172.     GetArcCoords(ArcInfo);
  173.     with ArcInfo do
  174.     begin
  175.       Line(X, Y, XStart, YStart);
  176.       Line(X, Y, Xend, Yend);
  177.     end;
  178.   until KeyPressed;
  179.   WaitToGo;
  180. end; { ArcPlay }
  181.  
  182. procedure PutPixelPlay;
  183. { Demonstrate the PutPixel and GetPixel commands }
  184. const
  185.   Seed   = 1962; { A seed for the random number generator }
  186.   NumPts = 2000; { The number of pixels plotted }
  187.   Esc    = #27;
  188. var
  189.   I : word;
  190.   X, Y, Color : word;
  191.   XMax, YMax  : integer;
  192.   ViewInfo    : ViewPortType;
  193. begin
  194.   MainWindow('PutPixel / GetPixel demonstration');
  195.   StatusLine('Esc aborts or press a key...');
  196.  
  197.   GetViewSettings(ViewInfo);
  198.   with ViewInfo do
  199.   begin
  200.     XMax := (x2-x1-1);
  201.     YMax := (y2-y1-1);
  202.   end;
  203.  
  204.   while not KeyPressed do
  205.   begin
  206.     { Plot random pixels }
  207.     RandSeed := Seed;
  208.     I := 0;
  209.     while (not KeyPressed) and (I < NumPts) do
  210.     begin
  211.       Inc(I);
  212.         PutPixel(Random(XMax)+1, Random(YMax)+1, RandColor);
  213.     end;
  214.  
  215.     { Erase pixels }
  216.     RandSeed := Seed;
  217.     I := 0;
  218.     while (not KeyPressed) and (I < NumPts) do
  219.     begin
  220.       Inc(I);
  221.       X := Random(XMax)+1;
  222.       Y := Random(YMax)+1;
  223.       Color := GetPixel(X, Y);
  224.         if Color = RandColor then
  225.           PutPixel(X, Y, 0);
  226.      end;
  227.   end;
  228.   WaitToGo;
  229. end; { PutPixelPlay }
  230.  
  231. procedure PutImagePlay;
  232. { Demonstrate the GetImage and PutImage commands }
  233.  
  234. const
  235.   r  = 20;
  236.   StartX = 100;
  237.   StartY = 50;
  238.  
  239. var
  240.   CurPort : ViewPortType;
  241.  
  242. procedure MoveSaucer(var X, Y : integer; Width, Height : integer);
  243. var
  244.   Step : integer;
  245. begin
  246.   Step := Random(2*r);
  247.   if Odd(Step) then
  248.     Step := -Step;
  249.   X := X + Step;
  250.   Step := Random(r);
  251.   if Odd(Step) then
  252.     Step := -Step;
  253.   Y := Y + Step;
  254.  
  255.   { Make saucer bounce off viewport walls }
  256.   with CurPort do
  257.   begin
  258.     if (x1 + X + Width - 1 > x2) then
  259.       X := x2-x1 - Width + 1
  260.     else
  261.       if (X < 0) then
  262.         X := 0;
  263.     if (y1 + Y + Height - 1 > y2) then
  264.       Y := y2-y1 - Height + 1
  265.     else
  266.       if (Y < 0) then
  267.         Y := 0;
  268.   end;
  269. end; { MoveSaucer }
  270.  
  271. var
  272.   Pausetime : word;
  273.   Saucer    : pointer;
  274.   X, Y      : integer;
  275.   ulx, uly  : word;
  276.   lrx, lry  : word;
  277.   Size      : word;
  278.   I         : word;
  279. begin
  280.   ClearDevice;
  281.   FullPort;
  282.  
  283.   { PaintScreen }
  284.   ClearDevice;
  285.   MainWindow('GetImage / PutImage Demonstration');
  286.   StatusLine('Esc aborts or press a key...');
  287.   GetViewSettings(CurPort);
  288.  
  289.   { DrawSaucer }
  290.   Ellipse(StartX, StartY, 0, 360, r, (r div 3)+2);
  291.   Ellipse(StartX, StartY-4, 190, 357, r, r div 3);
  292.   Line(StartX+7, StartY-6, StartX+10, StartY-12);
  293.   Circle(StartX+10, StartY-12, 2);
  294.   Line(StartX-7, StartY-6, StartX-10, StartY-12);
  295.   Circle(StartX-10, StartY-12, 2);
  296.   SetFillStyle(SolidFill, MaxColor);
  297.   FloodFill(StartX+1, StartY+4, GetColor);
  298.  
  299.   { ReadSaucerImage }
  300.   ulx := StartX-(r+1);
  301.   uly := StartY-14;
  302.   lrx := StartX+(r+1);
  303.   lry := StartY+(r div 3)+3;
  304.  
  305.   Size := ImageSize(ulx, uly, lrx, lry);
  306.   GetMem(Saucer, Size);
  307.   GetImage(ulx, uly, lrx, lry, Saucer^);
  308. {  PutImage(ulx, uly, Saucer^, XORput);               { erase image }
  309.  
  310.   { Plot some "stars" }
  311.   for I := 1 to 1000 do
  312.      PutPixel(Random(MaxX), Random(MaxY), RandColor);
  313.   X := MaxX div 2;
  314.   Y := MaxY div 2;
  315.   PauseTime := 70;
  316.  
  317.   { Move the saucer around }
  318.   repeat
  319. {     PutImage(X, Y, Saucer^, XORput);                 { draw image }
  320.      Delay(PauseTime);
  321. {     PutImage(X, Y, Saucer^, XORput);                 { erase image }
  322.      MoveSaucer(X, Y, lrx - ulx + 1, lry - uly + 1);  { width/height }
  323.   until KeyPressed;
  324.   FreeMem(Saucer, size);
  325.   WaitToGo;
  326. end; { PutImagePlay }
  327.  
  328. procedure PolyPlay;
  329. { Draw random polygons with random fill styles on the screen }
  330. const
  331.   MaxPts = 5;
  332. type
  333.   PolygonType = array[1..MaxPts] of PointType;
  334. var
  335.   Poly : PolygonType;
  336.   I, Color : word;
  337. begin
  338.   MainWindow('FillPoly demonstration');
  339.   StatusLine('Esc aborts or press a key...');
  340.   repeat
  341.     Color := RandColor;
  342.     SetFillStyle(Random(11)+1, Color);
  343.     SetColor(Color);
  344.     for I := 1 to MaxPts do
  345.       with Poly[I] do
  346.       begin
  347.         X := Random(MaxX);
  348.         Y := Random(MaxY);
  349.       end;
  350.     FillPoly(MaxPts, Poly);
  351.   until KeyPressed;
  352.   WaitToGo;
  353. end; { PolyPlay }
  354.  
  355. procedure FillStylePlay;
  356. { Display all of the predefined fill styles available }
  357. var
  358.   Style    : word;
  359.   Width    : word;
  360.   Height   : word;
  361.   X, Y     : word;
  362.   I, J     : word;
  363.   ViewInfo : ViewPortType;
  364.  
  365. procedure DrawBox(X, Y : word);
  366. begin
  367.   SetFillStyle(Style, MaxColor);
  368.   with ViewInfo do
  369.     Bar(X, Y, X+Width, Y+Height);
  370.   Rectangle(X, Y, X+Width, Y+Height);
  371.   OutTextXY(X+(Width div 2), Y+Height+4, Int2Str(Style));
  372.   Inc(Style);
  373. end; { DrawBox }
  374.  
  375. begin
  376.   MainWindow('Pre-defined fill styles');
  377.   GetViewSettings(ViewInfo);
  378.   with ViewInfo do
  379.   begin
  380.     Width := 2 * ((x2+1) div 13);
  381.     Height := 2 * ((y2-10) div 10);
  382.   end;
  383.   X := Width div 2;
  384.   Y := Height div 2;
  385.   Style := 0;
  386.   for J := 1 to 3 do
  387.   begin
  388.     for I := 1 to 4 do
  389.     begin
  390.       DrawBox(X, Y);
  391.       Inc(X, (Width div 2) * 3);
  392.     end;
  393.     X := Width div 2;
  394.     Inc(Y, (Height div 2) * 3);
  395.   end;
  396.   SetTextJustify(LeftText, TopText);
  397.   WaitToGo;
  398. end; { FillStylePlay }
  399.  
  400. procedure FillPatternPlay;
  401. { Display some user defined fill patterns }
  402. const
  403.   Patterns : array[0..11] of FillPatternType = (
  404.   ($AA, $55, $AA, $55, $AA, $55, $AA, $55 üÖü üÖü  !BBäx!!!BBäx!BBäx"""DDêp""DDêp>"""BBääêp""!"BDäêêp>IÉÆ|      ° @≥î>00>><Dêx  !BBäx""DDêp&<"DDêê&22TTêêê$> $< @äêp>          ⁿBBBB<  @@Ç****DDDDDDDU¬U¬U¬U¬U¬U¬U¬▌w▌w▌w▌w▌w▌w▌w°°°≥■°°≥≥■≥≥■■°°°    ≤  ≤  ≤≤         °                     ≡≡≡≡≡≡≡≡≡≡≡≡≡≡       ;DDD;    $"Bdÿ>@@@>||>Ac]AAA1N"A""2,  `1NA"*III*<Bü üB<<BüüüB<A" \"QIE" < <BBBB  @@    ~ ?  @ÇB$$B ""A$$"AII6 üBr»$**IIII**ccregion.  The region is defined as any pixel of
  405.             OldColor which has a path of pixels of OldColor or NewColor
  406.             with sides touching back to the seed point, (XSeed, YSeed).
  407.             Therefore, only pixels of OldColor are modified and no other
  408.             information is changed.
  409.  
  410.             SEE ALSO
  411.  
  412.             DRWFILLBOX, DRWFILLCIRCLE, DRWFILLELLIPSE, FILLAREA,
  413.             FILLCONVEXPOLY, FILLPAGE, FILLPOLY, FILLSCREEN, FILLVIEW,
  414.             SETVIEW
  415.  
  416.             EXAMPL(HNxHHO$B<BBBB<$<BBBB<<BBBB<$BBBBBF:0BBBBF:$BBBF:B<""AAA""AAAAA"<B@@B<" <2\A">>xDDxDNDD <` <>BB= > <BBBB< BBBBF:2L\bBBBB&AaQIECA8$>""">0@@A>@@@ b$(. b$(*
  417.     $    $    $DDDDDDD¬U¬U¬U¬U¬U¬U¬Uw▌w▌w▌w▌w▌w▌w▌°°°⌠ⁿ°°⌠⌠ⁿ⌠⌠ⁿⁿ°°°    ≈  ≈  ≈≈         °                     ≡≡≡≡≡≡≡≡≡≡≡≡≡≡       7HH7"B\DBBRL~BB@@@@@@?R~!!~?DDDD8BBBB|@@Ç>P>III>"AA""AAA"Uw<DDDD86II6"EIQ"\ @@ "AAAAA> >     hH02L2L$$<H(,$<>>>>>>>         VMODE=VIDEOMODEGET
  418.             IF WHICHVGA = 0 THEN STOP
  419.             DUMMY=RES640
  420.             SETVIEW 100, 100, 539, 379
  421.             FILLVIEW 10
  422.             WHILE INKEY$ = ""
  423.             WEND
  424.             VIDEOMODESET VMODE
  425.             END
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.                                                                          63
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.           FONTGETINFO
  450.  
  451.             PROTOTYPE
  452.  
  453.             SUB FONTGETINFO (Width%, Height%)
  454.  
  455.             INPUT
  456.  
  457.             no input parameters
  458.     WEND
  459.             MOUSEEXIT
  460.             VIDEOMODESET VMODE
  461.             END
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.